149 lines
4.8 KiB
TypeScript
149 lines
4.8 KiB
TypeScript
"use client";
|
|
|
|
import { ColumnDef } from "@tanstack/react-table";
|
|
import { Button } from "@app/components/ui/button";
|
|
import {
|
|
ArrowUpDown,
|
|
MoreHorizontal,
|
|
} from "lucide-react";
|
|
import { PolicyDataTable } from "./PolicyDataTable";
|
|
import {
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuItem,
|
|
DropdownMenuTrigger
|
|
} from "@app/components/ui/dropdown-menu";
|
|
import { InfoPopup } from "@app/components/ui/info-popup";
|
|
|
|
export interface PolicyRow {
|
|
orgId: string;
|
|
roleMapping?: string;
|
|
orgMapping?: string;
|
|
}
|
|
|
|
interface Props {
|
|
policies: PolicyRow[];
|
|
onDelete: (orgId: string) => void;
|
|
onAdd: () => void;
|
|
onEdit: (policy: PolicyRow) => void;
|
|
}
|
|
|
|
export default function PolicyTable({ policies, onDelete, onAdd, onEdit }: Props) {
|
|
const columns: ColumnDef<PolicyRow>[] = [
|
|
{
|
|
id: "dots",
|
|
cell: ({ row }) => {
|
|
const r = row.original;
|
|
|
|
return (
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button variant="ghost" className="h-8 w-8 p-0">
|
|
<span className="sr-only">Open menu</span>
|
|
<MoreHorizontal className="h-4 w-4" />
|
|
</Button>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent align="end">
|
|
<DropdownMenuItem
|
|
onClick={() => {
|
|
onDelete(r.orgId);
|
|
}}
|
|
>
|
|
<span className="text-red-500">Delete</span>
|
|
</DropdownMenuItem>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
);
|
|
}
|
|
},
|
|
{
|
|
accessorKey: "orgId",
|
|
header: ({ column }) => {
|
|
return (
|
|
<Button
|
|
variant="ghost"
|
|
onClick={() =>
|
|
column.toggleSorting(column.getIsSorted() === "asc")
|
|
}
|
|
>
|
|
Organization ID
|
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
|
</Button>
|
|
);
|
|
}
|
|
},
|
|
{
|
|
accessorKey: "roleMapping",
|
|
header: ({ column }) => {
|
|
return (
|
|
<Button
|
|
variant="ghost"
|
|
onClick={() =>
|
|
column.toggleSorting(column.getIsSorted() === "asc")
|
|
}
|
|
>
|
|
Role Mapping
|
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
|
</Button>
|
|
);
|
|
},
|
|
cell: ({ row }) => {
|
|
const mapping = row.original.roleMapping;
|
|
return mapping ? (
|
|
<InfoPopup
|
|
text={mapping.length > 50 ? `${mapping.substring(0, 50)}...` : mapping}
|
|
info={mapping}
|
|
/>
|
|
) : (
|
|
"--"
|
|
);
|
|
}
|
|
},
|
|
{
|
|
accessorKey: "orgMapping",
|
|
header: ({ column }) => {
|
|
return (
|
|
<Button
|
|
variant="ghost"
|
|
onClick={() =>
|
|
column.toggleSorting(column.getIsSorted() === "asc")
|
|
}
|
|
>
|
|
Organization Mapping
|
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
|
</Button>
|
|
);
|
|
},
|
|
cell: ({ row }) => {
|
|
const mapping = row.original.orgMapping;
|
|
return mapping ? (
|
|
<InfoPopup
|
|
text={mapping.length > 50 ? `${mapping.substring(0, 50)}...` : mapping}
|
|
info={mapping}
|
|
/>
|
|
) : (
|
|
"--"
|
|
);
|
|
}
|
|
},
|
|
{
|
|
id: "actions",
|
|
cell: ({ row }) => {
|
|
const policy = row.original;
|
|
return (
|
|
<div className="flex items-center justify-end">
|
|
<Button
|
|
variant={"outlinePrimary"}
|
|
className="ml-2"
|
|
onClick={() => onEdit(policy)}
|
|
>
|
|
Edit
|
|
</Button>
|
|
</div>
|
|
);
|
|
}
|
|
}
|
|
];
|
|
|
|
return <PolicyDataTable columns={columns} data={policies} onAdd={onAdd} />;
|
|
}
|